package test;
import parser.Procedure;
import parser.Block;
import parser.Id;
import parser.Assign;
import parser.List;
import parser.Mul;
import parser.Numeral;
import parser.Opt;
import parser.MiniPVisitor;
import parser.SimpleNode;
import parser.Start;
import parser.Print;
import parser.Less;
import parser.Add;

class MSNVisitor implements MiniPVisitor {
	
	public Object visit(SimpleNode node, Object data) {
        return null;
    }
	
	public Object visit(Print node, Object data) {
		return node.getExp().jjtAccept(this, data);
	}
	
	public Object visit(Start node, Object data) {
        return node.getProcedure().jjtAccept(this, data);
    }
	
	public Object visit(Procedure node, Object data) {
		return node.getBlock().jjtAccept(this, data);
	}
    
    public Object visit(Block node, Object data) {
    	int count = node.getNumStmt();
    	int max = 0;
    	for(int i = 0; i<count; i++)
    	{
    		if ((Integer) node.getStmt(i).jjtAccept(this, data) > max) max = (Integer) node.getStmt(i).jjtAccept(this, data); 
    	}
    	
        return max;
    }
    
    public Object visit(Assign node, Object data) {
    	return node.getExp().jjtAccept(this, data);
    }
    
    public Object visit(Mul node, Object data) {
        int left = (Integer) node.getLeft().jjtAccept(this, data) + 1;
        int right = (Integer) node.getRight().jjtAccept(this, data) + 1;
        return new Integer (left>right ? left : right);
    }
    
    public Object visit(Add node, Object data) {
        int left = (Integer) node.getLeft().jjtAccept(this, data) + 1;
        int right = (Integer) node.getRight().jjtAccept(this, data) + 1;
        return new Integer (left>right ? left : right);
    }
    
    public Object visit(Less node, Object data) {
        int left = (Integer) node.getLeft().jjtAccept(this, data) + 1;
        int right = (Integer) node.getRight().jjtAccept(this, data) + 1;
        return new Integer (left>right ? left : right);
    }
    
    public Object visit(Numeral node, Object data) {
        return 1;
    }

    public Object visit(Id node, Object data) {
        return 1;
    }


	@Override
	public Object visit(List node, Object data) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public Object visit(Opt node, Object data) {
		// TODO Auto-generated method stub
		return null;
	}
}
